package ch.kerbtier.malurus.operations;

import java.util.HashSet;
import java.util.Set;

import ch.kerbtier.malurus.Visitor;
import ch.kerbtier.malurus.Component;
import ch.kerbtier.malurus.CompositeComponent;

public class CollectChangesVisitor implements Visitor {
	private Set<Component> collectedComponents = new HashSet<Component>();

	public void visit(Component component) {
		if (component.modified()) {
			collectedComponents.add(component);
		}
	}

	public void visit(CompositeComponent compositeComponent) {
		if (compositeComponent.modified()) {
			collectedComponents.add(compositeComponent);
		} else {
			for (Component c : compositeComponent) {
				c.acceptVisitor(this);
			}
		}
	}

	public Set<Component> getCollectedComponents() {
		return collectedComponents;
	}
}
